/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.raytracer;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author drafkind
 */
public class Union extends VisibleObject {
  private List<VisibleObject> objects;
  
  public Union() {
    objects = new ArrayList<VisibleObject>();
  }
  
  public List<IntersectionPoint> getIntersectionPoints(Ray ray) {
    List<IntersectionPoint> points = new ArrayList<IntersectionPoint>();
    for (VisibleObject vo : objects) {
      points.addAll(vo.getIntersectionPoints(ray));
    }

    return points;
  }

  public Vector3 getNormalAt(IntersectionPoint where) {
    return where.getTarget().getNormalAt(where);
  }

  @Override public void setTexture(Texture texture) {
    this.texture = texture;

    for (VisibleObject vo : objects) {
      vo.setTexture(texture);
    }
  }  

  @Override public boolean isInsideImplementation(Vector3 where) {
    for (VisibleObject vo : objects) {
      if (vo.isInside(where))
        return true;
    }
    return false;
  }

  public List<VisibleObject> getObjects() {
    return objects;
  }
}